jQuery(document).ready(function() {

    //1.初始化Table
    var oTable = new ParamTableInit();
    oTable.Init();
    //初始化页面
    ParamInit.init();
    batchImport.init();
});

var ParamTableInit = function(){
    var oTableInit = new Object();
    $(".queryEuqipModel").trigger('change');
    //初始化Table，发出请求查询数据
    oTableInit.Init = function () {
        $('#paramTable').bootstrapTable({
            url: ctx +'/equipment/param/listEuipmentParam/get.mvc',         //请求后台的URL（*）
            method: 'get',                      //请求方式（*）
//            toolbar: '#toolbar',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,                   //是否显示分页（*）
            paginationLoop:false,
            sortable: true,                     //是否启用排序
            sortOrder: "asc",                   //排序方式
            queryParams: oTableInit.queryParams,//传递参数（*）
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber:1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
            search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            strictSearch: true,
            showColumns: false,                  //是否显示所有的列
            showRefresh: false,                  //是否显示刷新按钮
            minimumCountColumns: 2,             //最少允许的列数
            clickToSelect: true,                //是否启用点击选中行
            height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "pkId",                     //每一行的唯一标识，一般为主键列
            showToggle:false,                    //是否显示详细视图和列表视图的切换按钮
            cardView: false,                    //是否显示详细视图
            detailView: false,                   //是否显示父子表
            singleSelect:false,                    //禁止多选
            checkboxHeader:true,                 //列头取消多选


            columns: [
                {
                    checkbox:true,
                    align : 'center',
                    valign : 'middle',
                },
                {
                    title: '序号',
                    align : 'center',
                    valign : 'middle',
                    formatter : function (value, row, index){
                        var options = $('#paramTable').bootstrapTable('getOptions');
                        return options.pageSize * (options.pageNumber - 1) + index + 1;
                    }
                },
                {
                    field: 'modelCode',
                    title: '设备型号',
                    sortable:false,
                    align : 'center',
                    valign : 'middle',

                }, {
                    field: 'modelType',
                    title: '设备类别',
                    sortable:false,
                    align : 'center',
                    valign : 'middle',
                    formatter : function(value,row,index){
                        if(value == "1"){
                            return "生产类";
                        }else if(value=="2"){
                            return "环境类";
                        }else if(value=="3"){
                            return "能源类";
                        }else if(value=="4"){
                            return "检测类";
                        }else if(value=="5"){
                            return "生产辅助类";
                        }
                    }
                }, {
                    field: 'paramName',
                    title: '参数名称',
                    sortable:false,
                    align : 'center',
                    valign : 'middle',
                },  {
                    field: 'paramCode',
                    title: '参数编号',
                    sortable:false,
                    align : 'center',
                    valign : 'middle',
                }, {
                    field: '',
                    title: '采集地址',
                    sortable:false,
                    align : 'center',
                    valign : 'middle',
                    formatter : function(value,row,index){

                        //隐藏html

                        return "<a href='#' class='showCollectionAddr' data-data='"+JSON.stringify(row)+"'>查看</a>";
                    }
                }, {
                    field: 'collectionType',
                    title: '采集方式',
                    sortable:false,
                    align : 'center',
                    valign : 'middle',
                    formatter : function(value, row, index) {

                        if (value === "1" ) {
                            return "PLC";
                        }
                        if (value === "2" ) {
                            return "文件";
                        }
                        if (value === "3" ) {
                            return "数据库";
                        }
                        if (value === "4" ) {
                            return "上位机";
                        }

                    }
                }, {
                    field: 'processRange',
                    title: '工艺范围(单位)',
                    sortable:false,
                    align : 'center',
                    valign : 'middle',
                }, {
                    field: 'enlargeNum',
                    title: '缩放比例',
                    sortable:false,
                    align : 'center',
                    valign : 'middle',
                }, {
                    field: 'dataType',
                    title: '数据类型',
                    sortable:false,
                    align : 'center',
                    valign : 'middle',
                },{
                    field: 'rwAttr',
                    title: '读写属性',
                    sortable:false,
                    align : 'center',
                    valign : 'middle',
                    formatter : function(value, row, index) {
                        if (value === 0 ) {
                            return "只读";
                        }else if(value === 1){
                            return "只写";
                        }else{
                            return "可读可写";
                        }

                    }
                }/*, {
                field: 'isAutoAlarm',
                title: '是否自动告警',
                sortable:false,
                align : 'center',
                valign : 'middle',
                formatter : function(value, row, index){
                	return value=="0"?"是":"否";
                }
            }, {
                field: 'autoAlarmName',
                title: '告警名称定义',
                sortable:false,
                align : 'center',
                valign : 'middle',
            }*/,{
                    field: 'spcValue',
                    title: 'spc值',
                    sortable:false,
                    align : 'center',
                    valign : 'middle',
                },{
                    field: 'decimalPos',
                    title: '保留小数位',
                    sortable:false,
                    align : 'center',
                    valign : 'middle',
                },{
                    field: 'dataLength',
                    title: '数据位数',
                    sortable:false,
                    align : 'center',
                    valign : 'middle',
                },{
                    field: 'paramField',
                    title: 'dcs参数名',
                    sortable:false,
                    align : 'center',
                    valign : 'middle',
                }],

        });
    };
    //得到查询的参数
    oTableInit.queryParams = function (params) {
        var temp = {   // 这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            size: params.limit,   // 页面大小
            num: (params.offset/params.limit) + 1,  // 页码
            sort: params.sort,
            order: params.order,
            modelCode : $(".queryEuqipModel").val(),
            modelType : $("#paramModelType").val(),
            paramName : $("#paramName").val()
        };
        return temp;
    };
    return oTableInit;
};

var batchImport = function () {
    return {
        init: function () {
            batchImport._fileUpload();
        },

        _fileUpload: function () {
            $("#batchImportFile").fileinput({
                language: 'zh', //设置语言
                uploadUrl: ctx + '/equipment/param/batchImportParam/save.mvc', //上传的地址
                allowedFileExtensions: ['xls', 'xlsx'],//接收的文件后缀
                //uploadExtraData:{"id": 1, "fileName":'123.mp3'},
                uploadAsync: true, //默认异步上传
                showUpload: false, //是否显示上传按钮
                showRemove: false, //显示移除按钮
                showPreview: true, //是否显示预览
                showCaption: false,//是否显示标题
                browseClass: "btn btn-primary", //按钮样式
                dropZoneEnabled: false,//是否显示拖拽区域
                maxFileSize: 10 * 1024,//单位为kb，如果为0表示不限制文件大小
                //minFileCount: 1,
                maxFileCount: 1, //表示允许同时上传的最大文件个数
                enctype: 'multipart/form-data',
                validateInitialCount: false,
                previewFileIcon: "<iclass='glyphicon glyphicon-king'></i>",
                msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！"

            }).on("fileuploaded", function (event, data, previewId, index) {//上传成功后立即执行
                console.log(data);
                var response = data.response;
                if (response.result === false) {
                    $("#batchImportTips").css("color","red");
                } else {
                    $("#batchImportTips").css("color","green");
                }
                $("#batchImportTips").css("display", "block");
                $("#batchImportTips").text(response.message);
                $('.btn-file').hide();
            }).on('filesuccessremove', function (event, id) {//点击删除后立即执行
                $('.btn-file').show();
                $("#batchImportTips").text("");
                $("#batchImportTips").css("display", "none");
            });
        }
    }
}();

var ParamInit =function(){
    var dataTypeSelect2;
    var _initProcessRangeSelect2;
    return {
        init:function(){
            ParamInit.query();
            ParamInit.keyQuery();
            ParamInit.reset();
            ParamInit.refresh();
            ParamInit.del();
            ParamInit.add();
            ParamInit.update();
            ParamInit.validatorForm();
//			SystemCommon.getEmModel();
            SystemCommon.getQueryEquipModel();
            SystemCommon.changeEmModel();
            ParamInit.changeALarmSelect();
            _initProcessRangeSelect2 = ParamInit._initProcessRangeSelect2();
            ParamInit._batchImport();
            ParamInit._downloadFile();
            dataTypeSelect2 = ParamInit.getDataType();
        },

        //下载模板
        _downloadFile : function () {
            $("#downloadTemplate").on("click", function(e) {
                e.preventDefault();
                e.stopPropagation();
                window.location.href = ctx +"/equipment/param/downloadImportTemplate/get.mvc";
            });
        },
        _batchImport:function () {
            $("#batchImport").on("click",function () {
                $("#batchImportModal").modal();
            })
        },
        //条件查询
        query : function(){
            $("#queryParam").on("click","",function(){
                $('#paramTable').bootstrapTable('refreshOptions',{
                    pageNumber:1,
                });
            });
        },
        //按键触发查询
        keyQuery : function(){
            $(".queryParam").keypress(function (e) {
                if (e.which == 13) {
                    $("#queryParam").trigger("click");
                }
            });
        },
        //重置功能
        reset : function() {
            $("#resetParam").on("click","",function(){
                $(".clearfix input").val("");
                $("#viewEmModel").each(function(){
                    $("#viewEmModel").empty();
                    $("#viewEmModel").append("<option value=''></option>");
                    $('#viewEmModel').trigger('change.select2');
                });
                $("#paramModelType").val('');
            });
        },
        refresh : function(){
            //刷新
            $("#refreshParam").on("click",function(){
                $('#paramTable').bootstrapTable('refresh');
            });
        },
        getDataType :function() {
            var select2 = $('.dataType').select2({
                ajax: {
                    url: ctx +'/equipment/param/getDataType/get.mvc',
                    dataType: 'json',
                    aynsc :false,
                    data: function (params) {
                        var query = {
                            search: params.term,
                            num: params.page || 1,
                            size:10
                        };
                        // Query parameters will be ?search=[term]&page=[page]
                        return query;
                    },
                    processResults: function (response) {
                        // Tranforms the top-level key of the response object from 'items' to 'results'
                        var test =new Array();
                        if(response&&response.data){
                            var data = response.data;
                            for ( var int = 0; int < data.length; int++) {
                                var obj=new Object();
                                obj.id=data[int].dictKey;
                                obj.text=data[int].dictValue;
                                test.push(obj);
                            }
                            var result = {
                                results: test
                            };
                            return result;
                        }
                        return null;

                    },
                    // Additional AJAX parameters go here; see the end of this chapter for the full code of this example
                    cache: true

                },
                placeholder: '请选择',
                language: "zh-CN",
                escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
                minimumInputLength: 0
            });
            return select2;

        },
        getQueryEquipModel : function(){
            var select2 = $('.processRange').select2({
                ajax: {
                    url: ctx +'/equipment/param/getProcessRange/get.mvc',
                    dataType: 'json',
                    data: function (params) {
                        var query = {
                            processRange: params.term,
                            num: params.page || 1,
                            size:10
                        };
                        return query;
                    },
                    processResults: function (data) {
                        var equipModelArr =new Array();
                        for ( var i = 0; i < data.length; i++) {
                            var obj = new Object();
                            obj.id=result.data[i].dictValue;
                            obj.text=result.data[i].dictValue;
                            equipModelArr.push(obj);
                        }
                        var result = {
                            results: equipModelArr
                        };
                        return result;
                    },
                    cache: true
                },
                placeholder: '请选择',
                language: "zh-CN",

                escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
                minimumInputLength: 0,
            });
            return select2;
        },
        //初始化equipCodeSelect2下拉框
        _initProcessRangeSelect2 : function () {
            var select2 = $(".processRange").select2({
                ajax: {
                    url: ctx +'/equipment/param/getProcessRange/get.mvc',
                    dataType: 'json',
                    data: function (params) {
                        var query = {
                            processRange: params.term,
                            num: params.page || 1,
                            size:10
                        };
                        return query;
                    },
                    processResults: function (result) {

                        var equipModelArr =new Array();
                        for ( var i = 0; i < result.data.length; i++) {
                            var obj = new Object();
                            obj.id=result.data[i].dictValue;
                            obj.text=result.data[i].dictValue;
                            equipModelArr.push(obj);
                        }
                        var result = {
                            results: equipModelArr
                        };
                        return result;
                    },
                    cache: true
                },
                placeholder: '请选择',
                language: "zh-CN",
                escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
                minimumInputLength: 0
            });
            return select2;
        },
        //删除设备类别
        del : function(){
            /**
             * 删除功能
             */
            $("#delParam").on("click","",function(){
                var ids = $.map($('#paramTable').bootstrapTable('getSelections'), function (row) {
                    return row.pkId;
                });
                if (ids.length <= 0 ) {
                    DialogUtil.ok("请选择需要操作的记录");
                    return;
                }
                DialogUtil.ok_and_cancel("是否删除?",function(){
                    $.ajax({
                        url: ctx + '/equipment/param/delCollectionParam/del.mvc',
                        type:"post",
                        dataType:'json',
                        data : {
                            pkId : ids.toString()
                        },
                        success : function(response){
                            if (response.result == true) {
                                DialogUtil.warning("删除成功");
                                $('#paramTable').bootstrapTable('refresh');
                            }else {
                                DialogUtil.warning(response.message+",不可删除!");
                            }
                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown){
                            DialogUtil.warning("系统错误");
                        }
                    });
                },function(){})
            });
        },
        //校验表单
        validatorForm : function(){
            $("#defaultForm").bootstrapValidator({
                message: 'This value is not valid',
                live: 'submitted',
                fields: {/*验证*/
                    modelCode: {
                        message: '设备型号无效',
                        validators: {
                            notEmpty: {
                                message: '请选择设备型号'
                            },
                        }
                    },
                    paramCode : {
                        message: '参数编号无效',
                        validators: {
                            notEmpty: {
                                message: '参数编号不能为空'
                            },
                        }
                    },
                    paramName: {
                        message: '参数名称无效',
                        validators: {
                            notEmpty: {
                                message: '参数名称不能为空'
                            },
                            stringLength: {
                                max: 20,
                                message: '参数名称不能超过20个字符'
                            }
                        }
                    },
                    dataLength: {
                        message: '数据位数无效',
                        validators: {
                            notEmpty: {
                                message: '数据位数不能为空'
                            },
                            stringLength: {
                                max: 20,
                                message: '数据位数不能超过20个字符'
                            }
                        }
                    },
                    paramField : {
                        message: 'DCS参数名无效',
                        validators: {
                            notEmpty: {
                                message: 'DCS参数名不能为空'
                            },
                            stringLength: {
                                max: 20,
                                message: 'DCS参数名不能超过20个字符'
                            }
                        }
                    },
                    decimalPos: {
                        message: '保留小数位无效',
                        validators: {
                            notEmpty: {
                                message: '保留小数位不能为空'
                            },
                            stringLength: {
                                max: 20,
                                message: '保留小数位不能超过20个字符'
                            }
                        }
                    },
                    collectionType: {
                        message: '采集方式无效',
                        validators: {
                            notEmpty: {
                                message: '采集方式不能为空'
                            },
                        }
                    },
                    plcAddr: {
                        message: 'PLC地址无效',
                        validators: {
                            notEmpty: {
                                message: 'PLC地址不能为空'
                            },
                        }
                    },
                    processRange: {
                        message: '工艺单位无效',
                        validators: {
                            notEmpty: {
                                message: '工艺单位不能为空'
                            },
                            stringLength: {
                                max: 20,
                                message: '工艺单位不能超过20个字符'
                            }
                        }
                    },
                    paramType: {
                        message: '采集项定义无效',
                        validators: {
                            notEmpty: {
                                message: '采集项不能为空'
                            }
                        }
                    },
                    dataType: {
                        message: '数据类型无效',
                        validators: {
                            notEmpty: {
                                message: '数据类型定义不能为空'
                            },
                            stringLength: {
                                max: 20,
                                message: '数据类型定义不能超过20个字符'
                            }
                        }
                    },
                    enlargeNum: {
                        message: '数据类型无效',
                        validators: {
                            notEmpty: {
                                message: '缩放比例不能为空'
                            }
                        }
                    }
                }
            });

            //模态框消失清空信息
            $("#myModal").on("hide.bs.modal",function(e){
                //输入框清空
                $('#myModal input').each(function() {
                    if ($(this).val() != "" || $(this).prop('checked') == true) {
                        $(this).val("").prop('checked', false);
                    }
                });
                $("#paramCode").attr("disabled",false);
                $('.processRange').val(null).trigger('change');
                $('.dataType').val(null).trigger('change');
                //移除采集方式对应的选择框
                $("#myModal .selectTypeRemove").remove();
                //设备型号改为请选择
                $("#myModal .emModelName").removeAttr("disabled");
                $('#myModal .emModelName').empty();
                $("#myModal .emModelName").append('<option value="">请选择</option>');
                //重置采集方式选项
                $('#myModal .collectionType').empty();
                $("#myModal .collectionType").append('<option value="">请选择</option>');
                $("#myModal .collectionType").append('<option value="1">PLC</option>');
                $("#myModal .collectionType").append('<option value="2">文件</option>');
                $("#myModal .collectionType").append('<option value="3">数据库</option>');
                $("#myModal .collectionType").append('<option value="4">上机</option>');
                //重置是否自动告警选项
                $('#myModal .isAutoAlarm').empty();
                $('#myModal .isAutoAlarm').append('<option value="0">是</option>');
                $('#myModal .isAutoAlarm').append('<option value="1">否</option>');
                $(".autoAlarmName").attr("disabled",false);
                //ParamInit.validatorForm();
                //清空校验
                $('#defaultForm').bootstrapValidator('resetForm', false);
                //开启校验对象
                //ParamInit.validatorForm();
            });
            $("#batchImportModal").on("hide.bs.modal",function(){
                $('.btn-file').show();
                $('.fileinput-remove').trigger('click');
                $('.error-tips').css("display", "none");
            });
        },
        //新增用户
        add : function(){
            //查看详情(查看采集地址)
            $('body').on("click",".showCollectionAddr",function(){
                var data = $(this).data("data");
                var html =template("showCollection",{data:data});
                $(".showCollectionFlag").remove();
                $("#myModal-addr .modal-body").append(html);
                $('#myModal-addr').modal();
            })

            //绑定切换
            $('body').on("change","#myModal .collectionType",function(){
                var data={};
                data.type=$("#myModal .collectionType option:selected").val();
                var html =template('selectType',{data:data});
                $("#myModal .selectTypeRemove").remove();
                $("#myModal .flag").after(html);

                //重新绑定校验
                if('1'==data.type){
                    $("#defaultForm").bootstrapValidator("addField","plcAddr",{
                        validators: {
                            notEmpty: {
                                message: 'plc地址不能为空'
                            }
                        }
                    });
                }else if('2'==data.type){

                    $("#defaultForm").bootstrapValidator("addField","fileColumn",{
                        validators: {
                            notEmpty: {
                                message: '列号不能为空'
                            }
                        }
                    });
                    $("#defaultForm").bootstrapValidator("addField","fileName",{
                        validators: {
                            notEmpty: {
                                message: '文件名不能为空'
                            }
                        }
                    });
                }else if('3'==data.type){

                    $("#defaultForm").bootstrapValidator("addField","databaseParamAddr",{
                        validators: {
                            notEmpty: {
                                message: '字段地址不能为空'
                            }
                        }
                    });
                }else if('4'==data.type){

                    $("#defaultForm").bootstrapValidator("addField","upperParamName",{
                        validators: {
                            notEmpty: {
                                message: '参数名称不能为空'
                            }
                        }
                    });
                    $("#defaultForm").bootstrapValidator("addField","upperParamField",{
                        validators: {
                            notEmpty: {
                                message: '参数字段不能为空'
                            }
                        }
                    });
                }
//				$('#defaultForm').data('bootstrapValidator').destroy();
                ParamInit.validatorForm();

            });


            //新增用户
            $("#addParam").on("click",function(){
                $('#myModal .modal-title').html("新增");
                $('#myModal').modal();

                //初始最新的选择（采集方式）
                var data={};
                data.type="";
                var html =template('selectType',{data:data});
                $("#myModal .flag").after(html);


                $("#myModal input[name='modelType']").attr("disabled",true);
                $(".paramForm .yes").attr("disabled",false);
                //初始化设备型号
                SystemCommon.getEmModel();
                $("#myModal .dataType").find("option[value='ushort']").attr("selected",true);
                $.fn.modal.Constructor.prototype.enforceFocus = function() {
                    $("#myModal select[name='modelCode']").focus();
                };
                //$('#defaultForm').data('bootstrapValidator').destroy();
                ParamInit.validatorForm();
            });
            //新增用户-确定
            $(".paramForm .yes").on(
                "click",
                function() {
                    $("#defaultForm").data("bootstrapValidator").validate();
                    var flag = $("#defaultForm").data("bootstrapValidator").isValid();
                    if(!flag){
                        //未通过验证
                        return false;
                    }
                    console.log($(".paramForm").serialize());
                    $("#myModal .yes").attr("disabled",true);
                    $("#myModal input[name='emModelType']").attr("disabled",false);
                    $("#myModal .emModelName").removeAttr("disabled");
                    $.ajax({
                        url : ctx + '/equipment/param/saveCollectionParam/save.mvc',
                        type : "post",
                        dataType : 'json',
                        data : $(".paramForm #defaultForm").serialize(),
                        success : function(response) {
                            if (response.result == true) {
                                DialogUtil.ok("保存成功");
                                //取消
                                $('#myModal').modal('hide');
                                $('#paramTable').bootstrapTable('refresh');
                            }else {
                                DialogUtil.warning(response.message);
                            }
                        },
                        error : function(XMLHttpRequest, textStatus, errorThrown) {

                            alert("系统错误");
                        }
                    });
                    return false;
                });
        },
        //修改用户
        update : function(){
            //修改用户
            $("#updateParam").on("click",function(){
                $('#myModal .modal-title').html("修改");
                var ids = $.map($('#paramTable').bootstrapTable('getSelections'), function (row) {
                    return row.pkId;
                });
                var emModels = $.map($('#paramTable').bootstrapTable('getSelections'), function (row) {
                    return row.modelCode;
                });
                console.log(ids.length);
                console.log(emModels);
                if (ids.length != 1 ) {
                    DialogUtil.warning("请选择一行修改");
                    return;
                }
                //初始化设备型号
                SystemCommon.getEmModel();
                setTimeout(function timeOut(){
                    $.ajax({
                        url: ctx +'/equipment/param/getEuipmentParamById/get.mvc',
                        type:"post",
                        dataType:'json',
                        data : {
                            pkId : ids.toString(),
                            modelCode: emModels.toString()
                        },
                        success : function(response){
                            console.log(response);
                            $('#myModal').modal();
                            $("#myModal input[name='modelType']").val(response.modelType);
                            $("#myModal input[name='paramName']").val(response.paramName);
                            $("#myModal input[name='paramCode']").val(response.paramCode);
                            $("#myModal input[name='paramRoute']").val(response.paramRoute);
                            $("#myModal input[name='plcAddr']").val(response.plcAddr);
                            $("#paramCode").attr("disabled",true);
                            var processRangeId = response.processRange;
                            var processRangeName = response.processRange;
                            if(processRangeId!=null&&processRangeName!=null) {
                                var option = new Option(processRangeName,processRangeId,true,true);
                                _initProcessRangeSelect2.append(option);
                                _initProcessRangeSelect2.trigger("change");
                            }
                            $("#myModal input[name='registerAddr']").val(response.registerAddr);
                            //默认id
                            $("#myModal input[name='pkId']").val(ids.toString());
                            //select2回显
                            $("#myModal .emModelName").val(response.modelCode).trigger("change");

                            //是否自动告警
                            $("#myModal .isAutoAlarm").find("option[value='"+response.isAutoAlarm+"']").attr("selected",true);
                            $("#myModal input[name='autoAlarmName']").val(response.autoAlarmName);
                            if(response.isAutoAlarm == '1'){
                                $(".autoAlarmName").attr("disabled",false);
                            }else{
                                $(".autoAlarmName").attr("disabled",true);
                            }

                            $("#myModal input[name='enlargeNum']").val(response.enlargeNum);
                            $("#myModal input[name='dataLength']").val(response.dataLength);
                            $("#myModal input[name='paramField']").val(response.paramField);
                            $("#myModal input[name='decimalPos']").val(response.decimalPos);
                            $("#myModal input[name='alarmCode']").val(response.alarmCode);
//				    	$("#myModal input[name='dataType']").val(response.dataType);

                            var dataType = response.dataType;
                            var dataTypeName = response.dataTypeName;
                            if(dataType!=null&&dataTypeName!=null) {
                                var option = new Option(dataTypeName,dataType,true,true);
                                dataTypeSelect2.append(option);
                                dataTypeSelect2.trigger("change");
                            }
                            $("#myModal input[name='spcValue']").val(response.spcValue);

                            //读写属性
                            $("#myModal .rwAttr").find("option[value='"+response.rwAttr+"']").attr("selected",true);

                            //选中对应的值
                            $("#myModal .collectionType").find("option[value='"+response.collectionType+"']").attr("selected","selected");
                            //初始最新的选择
                            var data={};
                            data.type=response.collectionType;
                            data.data=response;
                            var html =template('selectType',{data:data});
                            $("#myModal .flag").after(html);


                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown){
                            alert("系统错误");
                        }
                    });
                },100);
                $("#myModal .emModelName").attr("disabled","disabled");
                $("#myModal input[name='modelType']").attr("disabled",true);
                $(".paramForm .yes").attr("disabled",false);
            });
        },

        /**
         * 是否自动告警change事件
         */
        changeALarmSelect : function(){
            $(".isAutoAlarm").on("change","",function(){
                if($(".isAutoAlarm").val() =="0" ){
                    $(".autoAlarmName").attr("disabled",false);
//					$('.paramForm').data('bootstrapValidator').destroy();
                    ParamInit.validatorForm();
                    $('.paramForm #defaultForm').data('bootstrapValidator').enableFieldValidators("autoAlarmName",false,"");
                }else{
                    $(".autoAlarmName").attr("disabled",true);
                    $(".autoAlarmName").empty();
                    $('.paramForm #defaultForm').data('bootstrapValidator').enableFieldValidators("autoAlarmName",true,"");
                }
            });
        },

    };
}();


